package com.spring.rabbitmq.routing.topic;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.spring.rabbitmq.utils.RabbitMQUtils;
import lombok.SneakyThrows;

/**
 * @Author: lzx
 * @Data: 2021/04/29/10:18
 * @Description：
 */
public class Product {
    @SneakyThrows
    public static void main(String[] args) {
        Connection connection = RabbitMQUtils.getConnection();
        Channel channel = connection.createChannel();
        //声明交换机
        channel.exchangeDeclare("topics", "topic");
        //动态路由key
        String routeKey = "user.save";
        //发布消息
        channel.basicPublish("topics", routeKey, null, ("这是路由中的动态订阅模型,route key: [" + routeKey + "]").getBytes());
        //释放资源
        RabbitMQUtils.closeConnectionAndChannel(connection, channel);
    }
}
